package com.zpark.config;

import com.zpark.interceptor.MyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
    // 注册拦截器
    @Bean
    public MyInterceptor getMyInterceptor(){
        return new MyInterceptor();
    }

    // 将拦截器添加到拦截器链，指定拦截规则
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getMyInterceptor()).
                addPathPatterns("/*").
                excludePathPatterns("index").
                excludePathPatterns("error");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/tmp/**").addResourceLocations("file:/D://tmp/");
    }
}
